package com.zmj.sy.mom.srv.aps.utils;

import org.slf4j.helpers.MessageFormatter;
import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.StringUtils;

import java.util.Map;

public class PlaceHolderUtils {

    public static String getPlaceHolder(String message, Object... args){
        return MessageFormatter.arrayFormat(message, args).getMessage();
    }

    public static String replace(String message, Map<String, String> map) {
        if (!StringUtils.hasText(message)) {
            return message;
        }
        //定义${开头 ，}结尾的占位符
        PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}");
        //调用替换
        return propertyPlaceholderHelper.replacePlaceholders(message, map::get);
    }
}
